$(function(){
    var a = $('.mode').text();
    // var user = $('.user')
    // var password=$('.password')
    // console.log(user,password)
    $('#form').validate({
        errorElement:"span",
        errorPlacement: function(error, element) { 
                error.appendTo(element.parent()); 
        },
        rules:{
            user:{
                required:true,
                user:true
            },
            password:{
                required:true,
                password:true
            },
            checkbox:{
                required:true,
                checkbox:a
            }
        },
        messages:{
            user:{
            required:"用户名不能为空"
            },
            password:{
            required:"密码不能为空"
            },
            checkbox:{
            required:"验证码不能为空"
            }
        }, 
    })
    $('#forget').click(function(){
       $('#recall').attr('checked',false)
    })
    $('#logBtn').click(function(){
         console.log($('#user').val())
        if($('.logBtext').children().size()==7){
            var xhr = new XMLHttpRequest();
            xhr.open('POST','../php/qnh.login.php',true);
            xhr.setRequestHeader('Content-type','application/x-www-form-urlencoded');
            xhr.send('user='+$('#user').val()+'&password='+$('#password').val())
            xhr.onreadystatechange = function(){
                if(xhr.readyState==4&&xhr.status==200){
                    var data = JSON.parse(xhr.responseText)
                    if(data.status == "error"){
                            $('#logShow').text(data.msg)
                        }else{
                           if($('#recall').prop('checked')){
                                $.cookie("user",$('#user').val(),{expires:1,path:'/style'})
                                location.href=data.msg
                            }else {
                                $.cookie("user",$('#user').val())
                            }
                        }
                }
            }
        }
    })
})